<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body >

<h1>Test XmlParser</h1>
<hr size="0" />

<select name="getFromUrl" id="getFromUrl" >
<option value="1">Get From Url</option> 
<option selected value="0">Get from String</option>
</select>
<input type="text" value="fsm/stopwatch.xml" name="url" id="url"  />



<input type="button" value="run" name="cmd1" id="cmd1"  />
<br/>
<br/>
<div id="fsmdata" >
<fsm initial="{StopWatch.STATE_READY}">
	   <state name="{StopWatch.STATE_READY}" entering="{ApplicationFacade.RESET_DISPLAY}">
		   <transition action="{StopWatch.ACTION_START}" target="{StopWatch.STATE_RUNNING}"/>
	   </state>
	   <state name="{StopWatch.STATE_RUNNING}" entering="{ApplicationFacade.ENSURE_TIMER}">
		   <transition action="{StopWatch.ACTION_SPLIT}" target="{StopWatch.STATE_PAUSED}"/>
		   <transition action="{StopWatch.ACTION_STOP}"  target="{StopWatch.STATE_STOPPED}"/>
	   </state>
	   <state name="{StopWatch.STATE_PAUSED}" entering="{ApplicationFacade.FREEZE_DISPLAY}">
		   <transition action="{StopWatch.ACTION_UNSPLIT}" target="{StopWatch.STATE_RUNNING}"/>
		   <transition action="{StopWatch.ACTION_STOP}"     target="{StopWatch.STATE_STOPPED}"/>
	   </state>
	   <state name="{StopWatch.STATE_STOPPED}" entering="{ApplicationFacade.STOP_TIMER}">
		   <transition action="{StopWatch.ACTION_RESET}" target="{StopWatch.STATE_READY}"/>
	   </state>
</fsm>
</div>



<div id="result"></div>


<!-- Scripts --> 
<script type="text/javascript" src="js/objs.js"></script>
<script type="text/javascript" src="js/PureMVC_JS_1_0.js"></script>
<script type="text/javascript" src="js/PureMVC_JS_FSM_0_9.js"></script>

<script language="javascript" type="text/javascript" >

var cmd1 = document.getElementById("cmd1"); 
cmd1.onclick = function() {
	
	var FsmParser = Objs.load("org.puremvc.js.utilities.statemachine.FsmParser");
	
	var xmldoc = null;
	var parser = new FsmParser();
	
	var getFormUrl = document.getElementById("getFromUrl").value == 1 ;
	if(getFormUrl){
		var url = document.getElementById("url").value;
		xmldoc = parser.loadFromUrl(url);
	} else {	
		var xml = document.getElementById("fsmdata").innerHTML;
		xmldoc = parser.loadFromString(xml);
	}
	
	if(parser.status !== "error")
	{
		printf(parser.status);
	} else {
		printf(parser.status + " : " + parser.error);
	}
	
}



var pf = document.getElementById("result");
function printf(txt)
{
	var d = "";
	var currentTime = new Date()
	var hours = currentTime.getHours()
	var minutes = currentTime.getMinutes()
	if (minutes < 10){
	minutes = "0" + minutes
	}
	d += (hours + ":" + minutes + " ");
	if(hours > 11){
	d += ("PM");
	} else {
	d += ("AM");
	}


	pf.innerHTML = "[" + d + "] " +  txt + "<br/>" + pf.innerHTML ;
}
</script>



</body>
</html>
